package net.wang.concurrency.test.syncContainer;

import lombok.extern.slf4j.Slf4j;
import net.wang.concurrency.annoations.NotThreadSafe;
import net.wang.concurrency.annoations.ThreadSafe;
import org.junit.Test;

import java.util.List;
import java.util.Vector;


@SuppressWarnings("ALL")
@NotThreadSafe
@Slf4j
public class VectorExample2 {

    public static int clientTotal = 5000;
    public static int threadTotal = 200;
    public static List<Integer> list = new Vector<>();

    @Test
    public void notThreadSafeTest() throws InterruptedException {
        for (int j = 0; j < 10000; j++) {
            for (int i = 0; i < 10; i++) {
                list.add(i);
            }

            new Thread() {
                @Override
                public void run() {
                    for (int i = 0; i < list.size(); i++) {

                        list.remove(i);
                    }
                }
            }.start();

            new Thread() {
                @Override
                public void run() {
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i);
                    }
                }
            }.start();
        }

    }


}
